<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../easyUI/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../easyUI/themes/icon.css">
		<script type="text/javascript" src="../easyUI/jquery.min.js"></script>
		<script type="text/javascript" src="../easyUI/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../addressIP.js"></script>
		<script type="text/javascript" src="../datagrid-filter.js"></script>
		<script type="text/javascript" src="../easyUI/datagrid-export.js"></script>
	</head>
	<body>
		<table id="dg"></table>
		<script type="application/javascript">
			$('#dg').datagrid({
				columns: [
					[
						{
							field: 'studentName',
							title: '学生姓名',
							width: '8.66%',
							formatter: function(value, row, index) {
								if (row.student.name) {
									row.studentName = row.student.name;
									return row.student.name;
								}else{
									row.studentName = value;
									return value;
								}
							}
						},
						{
							field: 'studentClassName',
							title: '学生班级',
							width: '8.66%',
							formatter: function(value, row, index) {
								if (row.student.className) {
									row.studentClassName = row.student.className;
									return row.student.className;
								}else{
									row.studentClassName = value;
									return value;
								}
							}
						},
						{
							field: 'labNum',
							title: '实验室',
							width: '8.66%',
							formatter: function(value, row, index) {
								if (row.lab.labNum) {
									row.labNum = row.lab.labNum;
									return row.lab.labNum;
								}else{
									row.labNum = value;
									return value;
								}
							}
						},
						{
							field: 'messageInf',
							title: '申请说明',
							width: '10.66%',
							formatter: function(value) {
								return "<span title='" + value + "'>"+value + "</span>";
							}
						},
						{
							field: 'responseInf',
							title: '回复说明',
							width: '10.66%',
							formatter: function(value) {
								return "<span title='" + value + "'>"+value + "</span>";
							}
						}, {
							field: 'applyTime',
							title: '申请时间',
							width: '15.66%'
						}, {
							field: 'replyTime',
							title: '回复时间',
							width: '15.66%'
						}, {
							field: 'result',
							title: '申请结果',
							width: '10.66%',
							formatter: function(value, row, index) {
								if (row.result != null) {
									if(row.result=='0'){
										if (row.replyTime) {
											row.result = '拒绝申请';
											return "拒绝申请";
										}else{
											row.result = '等待教师审批';
											return "等待教师审批";
										}
									}else{
										row.result = '同意申请';
										return "同意申请";
									}
								}else{
									row.result = value;
									return value;
								}
							}
						}, {
							field: 'statement',
							title: '审批流程',
							width: '10.66%',
							formatter: function(value, row, index) {
								if (row.replyTime) {
									row.statement = '完成审批';
									return "完成审批";
								}else{
									row.statement = '尚未审批';
									return "尚未审批";
								}
							}
						}
					]
				]
			});
		</script>
		<script type="text/javascript">
			$(function() {
				var dg = $('#dg').datagrid({
					url: addressip + "/superGetLabMessage",
					queryParams: {
						superAccount: localStorage.getItem("superAccount"),
						password: localStorage.getItem("password")
					},
					fitColumns: true,
					loadMsg: '数据加载中^_^',
					striped: true, //显示斑马线
					loadMsg: '等等我。。',
					idField: 'userID',
					rownumbers: true,
					pagination: true,
					fit: true,
					fitColumns: true,
					checkbox: true,
					autoRowHeight: false,
					emptyMsg: '暂无数据',
					pageSize: 15,
					pageList: [15, 25, 50, 99999995]
				});
                var fbutton = dg.datagrid('getPager');
                fbutton.pagination({
                    buttons:[
                        {
                            iconCls: 'icon-redo',
                            handler: function() {
                                $.messager.confirm("操作提示", "本操作将导出展示的内容为Excel到Windows默认下载文件夹，可能需要等待较长时间，点击确定继续。", function(data) {
                                    if (data) {
                                        $('#dg').datagrid('toExcel', 'C:\Users\Public\Downloads\dg.xls');
                                    } else {
                                        $.messager.confirm("操作提示", "已取消");
                                    }
                                });
                            }
                        },{
                            iconCls: 'icon-clear',
                            handler: function() {
                                $("#dg").datagrid('clearSelections');
                            }
                        },{
                            iconCls: 'icon-ok',
                            handler: function() {
								selectedrowss = $('#dg').datagrid('getSelections');
								if(selectedrowss == null || selectedrowss.length == 0){
									$.messager.alert('提示','请选择未通过的申请','info');
								}else{
									if(selectedrowss.length > 1){
										$.messager.alert('提示','每次只能审批一条申请','info');
									}else{
										if(selectedrowss[0].result != "等待教师审批"){
											$.messager.alert('提示','审批学生申请，需选择尚未审批的记录','info');
										}else{
											$.messager.confirm({
												title:"申请审批",
												msg:"请选择审批结果",
												ok:"通过",
												cancel:"拒绝",
												fn:function (r) {
													var paremm = {};
													var teacherm = {};
													teacherm.teleNumber = localStorage.getItem("superAccount");
													teacherm.account = localStorage.getItem("superAccount");
													teacherm.password = localStorage.getItem("password");
													paremm.teacher = teacherm;
													paremm.labMessage = selectedrowss[0];
													if(r){
                                                        paremm.labMessage.result = 1;
                                                    }else{
													    paremm.labMessage.result = 0;
                                                    }
													$.ajax({
														type: 'post',
														dataType: 'json',
														url: addressip+"/judgeApply",
														headers:{
															'Content-Type':'application/json;charset=utf-8'
														},
														data: JSON.stringify(paremm),
														success: function (node) {
															if(node == "success"){
                                                                $.messager.alert('提示','审批成功！','info');
                                                            }
														}
													});
												}
											});
										}
									}
								}
                            }
                        }
                    ]
                });
			});

		</script>
	</body>
</html>
